package com.gzh.config;

import com.gzh.pojo.Pet;
import com.gzh.pojo.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;

import javax.annotation.Resource;

@Configuration(proxyBeanMethods = true)
@Import({User.class}) //用import导入的话，在容器中是全类名
@ImportResource("classpath:applicationContext.xml")
public class MyConfig {

    @Bean("user01")
    //给容器中添加组件。以方法名作为组件的id。返回类型就是组件类型。返回的值，就是组件在容器中的实例
    public User user01(){
        User zhangsan = new User();
        zhangsan.setName("zhangsan");
        zhangsan.setAge(18);
        //user组件依赖了Pet组件
        Pet pet = tomcatPet();
        zhangsan.setPet(pet);
        return zhangsan;
    }

    @Bean("tom")
    public Pet tomcatPet(){
        Pet pet = new Pet();
        pet.setName("tom");
        return pet;
    }

}
